package com.poor.film.service.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.poor.film.service.core.Result;
import com.poor.film.service.core.ResultGenerator;
import com.poor.film.service.model.PoorFilm;
import com.poor.film.service.model.request.PoorPageRequestBean;
import com.poor.film.service.service.PoorFilmService;
import com.poor.utils.PoorFileUtils;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
* Created by lcy on 2018/10/26.
*/
@RestController
@RequestMapping("/poor/film")
public class PoorFilmController {
    @Resource
    private PoorFilmService poorFilmService;

    @PostMapping("/add")
    public Result add(@RequestBody PoorFilm poorFilm) {
        poorFilmService.save(poorFilm);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    public Result delete(@RequestParam Integer id) {
        poorFilmService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody PoorFilm poorFilm) {
        poorFilmService.update(poorFilm);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        PoorFilm poorFilm = poorFilmService.findById(id);
        return ResultGenerator.genSuccessResult(poorFilm);
  }

    @PostMapping("/list")
    public Result list(@RequestBody PoorPageRequestBean poorPageRequestBean) {
        PageHelper.startPage(poorPageRequestBean.getPageNum(), poorPageRequestBean.getPageSize());
        List<PoorFilm> list = poorFilmService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo.getList());
    }
}
